package com.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

//切面类的定义
@Aspect
@Component
public class AspectByAno {
    @Pointcut("execution(* com.aop.*.*(..))")
    public void myPointCutByAno(){

    }

    @Before("myPointCutByAno()")
    public void myBefore(JoinPoint joinPoint) {
        System.out.println("*****前置通知myBefore******织入目标==" + joinPoint.getTarget());
    }
    @After("myPointCutByAno()")
    public void myAfter(JoinPoint joinPoint) {
        System.out.println("*****myAfter******织入目标==" + joinPoint.getTarget());
    }

    @AfterReturning("myPointCutByAno()")
    public void myAfterReturning(JoinPoint joinPoint) {
        System.out.println("*****后置返回通知myAfterReturning******织入目标==" +
                joinPoint.getSignature().getName());
    }
    @Around("myPointCutByAno()")
    public Object myAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("*****环绕通知开始********");
        Object obj = proceedingJoinPoint.proceed();
        System.out.println("*****环绕通知结束");
        return obj;

    }
    @AfterThrowing(value = "myPointCutByAno()",throwing = "e")
    public void myException(JoinPoint joinPoint,Throwable e) {
        System.out.println("*****myException******出错信息：" + e.getMessage());
    }
}
